﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HeathCareSystem.wuc
{
    public partial class wucThemToaThuoc : System.Web.UI.UserControl
    {
        int maChiTietBenhAn;
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnThemDS_Click(object sender, EventArgs e)
        {
            maChiTietBenhAn = 1;
            //them don thuoc
            //DonThuocDTO dtDTO = new DonThuocDTO();
            //dtDTO.ghiChu = "";
            //dtDTO.maChiTietBenhAn = maChiTietBenhAn;
            //new DonThuocDAO().ThemDonThuocMoi(dtDTO);

            //them chi tiet don thuoc
            string chiDinhThem = "";
            ChiTietDonThuocDTO ctdtDTO = new ChiTietDonThuocDTO();
            ctdtDTO.maDonThuoc = 1;
            ctdtDTO.maThuoc = 1;
            ctdtDTO.soLuong = int.Parse(txtSoLuong.Text);
            ctdtDTO.chiDinh1 = txtDung.Text;
            ctdtDTO.chiDinh2 = txtLan.Text;
            if(rbtnSauAn.Checked == true || rbtnTruocAn.Checked == true)
            {
                if(rbtnSauAn.Checked == true)
                    chiDinhThem = rbtnSauAn.Text;
                else
                    if(rbtnTruocAn.Checked == true)
                        chiDinhThem = rbtnTruocAn.Text;
            }
            ctdtDTO.chiDinhThem = chiDinhThem;
            
            new ChiTietDonThuocDAO().ThemChiTietDonThuocMoi(ctdtDTO);
            BenhNhanTrongNgayDTO bntn = BenhNhanTrongNgayBUS.LayThongTinTheoMa(txtMa.Text);  
            List<ChiTietDonThuocDTO> listThuoc = new List<ChiTietDonThuocDTO>();
            listThuoc = new ChiTietDonThuocDAO().DanhSachDonThuoc(bntn.maChiTietBenhAn, "wwew");

            gvDanhSach.DataSource = listThuoc;
            gvDanhSach.DataBind();         
        }

        protected void gvDanhSach_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int viTriDongDuocChon = e.RowIndex;
            int iMaChiTietDonThuoc = int.Parse(gvDanhSach.Rows[e.RowIndex].Cells[0].Text);
            //string maChiTietDonThuoc = gvDanhSach.SelectedRow.Cells[0].ToString();
            new ChiTietDonThuocDAO().XoaChiTietDonThuoc(iMaChiTietDonThuoc);

            List<ChiTietDonThuocDTO> listThuoc = new List<ChiTietDonThuocDTO>();
            listThuoc = new ChiTietDonThuocDAO().DanhSachDonThuoc(1, "jljlkjlkjl");

            gvDanhSach.DataSource = listThuoc;
            gvDanhSach.DataBind();
        }
    }
}